const fs = require('fs')
const path = require("path");

function saveImg(file, id = null) {
    const date = new Date().getTime()
    // 构建图片的完整路径
    let filePath = path.join(__dirname, '../public/blogImg/') + `${date + '.' + file.originalFilename.split('.')[1]}`;
    // 转为Buffer
    const fileBuffer = fs.readFileSync(file.filepath)
    fs.writeFileSync(filePath, fileBuffer);
    return /blogImg/ + `${date + '.' + file.originalFilename.split('.')[1]}`;
}


module.exports = saveImg
